package tests.pl.shenlon.ga;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

import pl.shenlon.ga.SimpleSpecimen;
import pl.shenlon.ga.Specimen;
import pl.shenlon.ga.StatefulChromosome;
import pl.shenlon.ga.StatefulSpecimen;
import pl.shenlon.poker.game.GameState;

public class StatefulSpecimenTest {
	private StatefulSpecimen specimen;

	@Before
	public void setUp() {
		specimen = new StatefulSpecimen();
	}

	@Test
	public void testConstructors() {
		specimen = new StatefulSpecimen();

		StatefulSpecimen copy = new StatefulSpecimen(specimen);
		Assert.assertNotSame(specimen, copy);
		Assert.assertNotSame(specimen.getGenom(), copy.getGenom());
		Assert.assertEquals(specimen, copy);
		copy.getGenom()
				.getBehaviourPattern(GameState.POSSIBLE_GAME_STATES.get(0))
				.setBluffChance(10000);
		Assert.assertFalse(specimen.equals(copy));

		copy = new StatefulSpecimen((StatefulChromosome) specimen.getGenom());
		Assert.assertNotSame(specimen, copy);
		Assert.assertNotSame(specimen.getGenom(), copy.getGenom());
		Assert.assertEquals(specimen, copy);
		copy.getGenom()
				.getBehaviourPattern(GameState.POSSIBLE_GAME_STATES.get(0))
				.setBluffChance(10000);
		Assert.assertFalse(specimen.equals(copy));
	}

	@Test
	public void testCopy() {
		StatefulSpecimen copy = (StatefulSpecimen) specimen.copy();
		Assert.assertNotSame(specimen, copy);
		System.out.println(specimen);
		System.out.println(copy);
		Assert.assertEquals(specimen, copy);
	}

	@Test(expected = IllegalArgumentException.class)
	public void testCrossover() {
		Specimen parentB = new SimpleSpecimen();
		specimen.crossover(0.0, parentB);
	}
}
